package licode.unisop.platform.utils;

import licode.unisop.provider.conf.SiAssetType;

/**
 * 管理ID生成
 *
 * @author WR
 * @since 2016/7/9 16:15
 */
public class AssetIdGenUtil {
    public static final int ID_SIZE = 20;
    public static final int ID_SIZE_DEFAULT = 20;

    public static String buildId(String assetType) {
        if (SiAssetType.AT_GROUP.equals(assetType)) {
            return getInnerId("GI", ID_SIZE);
        } else if (SiAssetType.AT_MENU.equals(assetType)) {
            return getInnerId("MU", ID_SIZE);
        } else if (SiAssetType.AT_PERMIT.equals(assetType)) {
            return getInnerId("PI", ID_SIZE);
        } else if (SiAssetType.AT_ROLE.equals(assetType)) {
            return getInnerId("RI", ID_SIZE);
        } else if (SiAssetType.AT_CLIENT.equals(assetType)) {
            return getInnerId("CI", ID_SIZE);
        } else if (SiAssetType.AT_PLATFORM.equals(assetType)) {
            return getInnerId("PL", ID_SIZE);
        } else if (SiAssetType.AT_TENANT.equals(assetType)) {
            return getInnerId("TI", ID_SIZE);
        } else if (SiAssetType.AT_URI.equals(assetType)) {
            return getInnerId("UI", ID_SIZE);
        } else {
            return getInnerId("SO", ID_SIZE);
        }
    }

    private static String getInnerId(String prefix) {
        return getInnerId(prefix, ID_SIZE_DEFAULT);
    }

    private static String getInnerId(String prefix, int size) {
        return prefix + java.util.UUID.randomUUID().toString()
                .trim().replaceAll("-", "").substring(0, size).toUpperCase();
    }
}
